export default (config = {}) => {
    return new Promise((resolve, reject) => {
        const { url, file, params = {} } = config;
        const fd = new FormData();
        fd.append('file', fd);
        Object.keys(params).forEach(k => {
            fd.append(k, params[k]);
        });
        const xhr = new XMLHttpRequest();
        xhr.onreadystatechange = function () {
            if (xhr.readyState === 4) {
                if (xhr.status === 200) {
                    resolve(JSON.parse(xhr.responseText))
                } else {
                    reject(JSON.parse(xhr.responseText));
                }
            }
        }
        xhr.open('POST',url);
        xhr.send(fd);
    })

}